﻿<cfsilent>
	<cfscript>
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		
		event.setArg("pageTitle", "学生调查问卷 - 在线调查设置向导 - 题目组织");
		
		questionId = event.getArg("QSN");
		quotaId = event.getArg("QUO");
		
		currentTab = event.getArg("TabID", "labQuota");
		
		passArgs = structNew();
		structInsert( passArgs, "QSN", questionId, true );
		
		sql = "	SELECT
					q.qsn_id,q.title
				FROM
					t_questionnaire q
				WHERE
					q.qsn_id = :questionId ";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "questionId", value = questionId, cfsqltype = "cf_sql_char");
		rs_quesEntity = queryObj.execute(sql = sql).getResult();
		
		rs_quotaEnrity = queryNew("quo_id");
		
		if ( len(quotaId) ) {
			structInsert( passArgs, "QUO", quotaId, true );

			sql = "	SELECT
						q.quo_id,q.question,q.measure
					FROM
						t_quota q
					WHERE
						q.quo_id = :quotaId ";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "quotaId", value = quotaId, cfsqltype = "cf_sql_varchar");
			rs_quotaEnrity = queryObj.execute(sql = sql).getResult();
			
		}

		sql = "	SELECT
					q.quo_id,q.question,q.measure
				FROM
					t_quota q
				WHERE
					q.qsn_id = :sheetId 
				ORDER BY
					q.quo_idx";
					
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "sheetId", value = questionId, cfsqltype = "cf_sql_char");
		rs_quota = queryObj.execute(sql = sql).getResult();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('voteList')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">调查问卷库</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>在线调查设置向导
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="findStudent">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labQuota">class="active"</cfif> id="labQuota" tabTarget="Quota">问卷题目组织</span>
						<span <cfif currentTab eq "labQuotaCreate">class="active"</cfif> id="labQuotaCreate" tabTarget="QuotaCreate">添加新问题</span>
						<cfif rs_quotaEnrity.recordCount>
							<span <cfif currentTab eq "labQuotaEdit">class="active"</cfif> id="labQuotaEdit" tabTarget="QuotaEdit">编辑问题</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
				
					});
					// -->
					//]]>
				</script>
				
				<div id="Quota" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton" href="<cfoutput>#buildURL('voteSetupWizardQuotaCreate', passArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">添加题目</span></a>
							<cfif rs_quota.recordCount>
								<a class="uiButton" href="<cfoutput>#buildURL('voteSetupWizardConfirm', passArgs)#</cfoutput>"><i class="mrs img btnDate"></i><span class="uiButtonText">时间及参与范围</span></a>
							</cfif>
						</div>
						<h3><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_quesEntity.title )#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>该问卷包含如下调查题目, 您也可以通过上方 "添加题目" 标签设置更多问题</p>
						<hr/>
					</div>
					
					<cfif rs_quota.recordCount>
							
							<cfset row = 0 />
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>问题</td>
										<td>选项</td>
										<td width="18"></td>
										<td width="18"></td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_quota">
										<cfset row++ />
										<cfset structInsert( passArgs, "QUO", rs_quota.quo_id, true ) />
										<tr class="editRows">
											<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
											<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_quota.question )#</cfoutput></td>
											<td nowrap="nowrap">
												<cfswitch expression="#rs_quota.measure#">
													<cfcase value="L1">
													是、否
													</cfcase>
													<cfcase value="L3">
													满意、基本满意、不满意
													</cfcase>
													<cfcase value="L4">
													优秀、较好、普通、不好
													</cfcase>
												</cfswitch>
											</td>
											
											<td>
												<!--- 若不是第一个 则可上移 --->
												<cfif row gt 1>
													<cfset structInsert( passArgs, "QUO_NEXT", rs_quota["quo_id"][row-1], true ) />
													<a class="stat up" href="<cfoutput>#buildURL('voteSetupWizardQuotaSwapDo', passArgs)#</cfoutput>"></a>
													<cfset structDelete( passArgs, "QUO_NEXT", false ) />
												</cfif>
											</td>
											
											<td>
												<!--- 若不是最后一个 则可上移 --->
												<cfif row lt rs_quota.recordCount>
													<cfset structInsert( passArgs, "QUO_NEXT", rs_quota["quo_id"][row+1], true ) />
													<a class="stat down" href="<cfoutput>#buildURL('voteSetupWizardQuotaSwapDo', passArgs)#</cfoutput>"></a>
													<cfset structDelete( passArgs, "QUO_NEXT", false ) />
												</cfif>
											</td>
											
											<td><a class="edit" href="<cfoutput>#buildURL('voteSetupWizardQuotaEdit', passArgs)#</cfoutput>"></a></td>
										</tr>
									</cfloop>
									<cfset structDelete( passArgs, "QUO", false ) />
								</tbody>
							</table>
							
						<cfelse>
							
							<div class="systemNotice">
								<p>该问卷还没有设置任何题目</p>
							</div>
							
					</cfif>
					
				</div>
				
				<div id="QuotaCreate" class="tabContent">
					
					<div class="noticeBlock">
						<h3>设置新问题</h3>
						<p><span class="img icon16x16 message"></span>设置问题时, 请注意预设答案的选择, 选择最符合问题语境的答案选项</p>
						<hr/>
					</div>
					
					<form id="formCreate" onSubmit="javascript:return processVerfiyForm('formCreate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('voteSetupWizardQuotaCreateDo')#</cfoutput>">
						
						<input type="hidden" name="QueID" value="<cfoutput>#rs_quesEntity.qsn_id#</cfoutput>" />

						<div class="label">
							<b>题目</b>
							<input name="Question" id="Question" verification="required" type="text" class="typeText" maxlength="180" value="<cfoutput>#event.getArg('Question')#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>选项</b>
							<div class="secondRow">
								<table>
									<tr>
										<td rowspan="4" width="90">预设答案</td>
									</tr>
									<tr>
										<td><input type="radio" name="Measure" class="typeRadio" value="L4" checked="checked" /> 优秀、较好、普通、不好</td>
									</tr>
									<tr>
										<td><input type="radio" name="Measure" class="typeRadio" value="L3" /> 满意、基本满意、不满意</td>
									</tr>
									<tr>
										<td><input type="radio" name="Measure" class="typeRadio" value="L1" /> 是、否</td>
									</tr>
								</table>
							</div>
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="添加" />
						</div>
						
					</form>
					
				</div>
				
				<cfif rs_quotaEnrity.recordCount>
					
					<cfset structInsert( passArgs, "QUO", rs_quotaEnrity.quo_id, true ) />
					
					<div id="QuotaEdit" class="tabContent">
					
						<div class="noticeBlock">
							<h3>编辑现有问题</h3>
							<p><span class="img icon16x16 message"></span>设置问题时, 请注意预设答案的选择, 选择最符合问题语境的答案选项</p>
							<hr/>
						</div>
						
						<form id="formUpdate" onSubmit="javascript:return processVerfiyForm('formUpdate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('voteSetupWizardQuotaUpdateDo')#</cfoutput>">
							
							<input type="hidden" name="QueID" value="<cfoutput>#rs_quesEntity.qsn_id#</cfoutput>" />
							<input type="hidden" name="QuotaID" value="<cfoutput>#rs_quotaEnrity.quo_id#</cfoutput>" />
							
							<div class="label">
								<b>题目</b>
								<input name="Question" id="Question" verification="required" type="text" class="typeText" maxlength="180" value="<cfoutput>#stringAdvice.HTMLFormEncode( event.getArg( 'Question', rs_quotaEnrity.question ) )#</cfoutput>" />
							</div>
						
							<div class="label">
								<b>选项</b>
								<div class="secondRow">
									<table>
										<tr>
											<td rowspan="4" width="90">预设答案</td>
										</tr>
										<tr>
											<td><input type="radio" name="Measure" class="typeRadio" value="L4" <cfif event.getArg( 'Measure', rs_quotaEnrity.measure ) eq "L4">checked="checked"</cfif> /> 优秀、较好、普通、不好</td>
										</tr>
										<tr>
											<td><input type="radio" name="Measure" class="typeRadio" value="L3" <cfif event.getArg( 'Measure', rs_quotaEnrity.measure ) eq "L3">checked="checked"</cfif> /> 满意、基本满意、不满意</td>
										</tr>
										<tr>
											<td><input type="radio" name="Measure" class="typeRadio" value="L1" <cfif event.getArg( 'Measure', rs_quotaEnrity.measure ) eq "L1">checked="checked"</cfif> /> 是、否</td>
										</tr>
									</table>
								</div>
							</div>
						
							<hr/>
						
							<div class="lable">
								<input class="button" type="submit" value="更新" />
								<a class="button2" href="<cfoutput>#buildURL('voteSetupWizardQuotaDeleteDo', passArgs)#</cfoutput>">删除</a>
							</div>

						</form>
						
					</div>
						
				</cfif>

			</div>
		</li>
	</ul>
</div>